package lc_2844_生成特殊数字的最少操作;

public class Solution {

    public int minimumOperations(String num) {
        char[] nums = num.toCharArray();
        boolean z = false, f = false;
        // 0,00,25,50,75
        for (int i = nums.length - 1; i > -1; i--) {
            char c = nums[i];
            if (c == '0') {
                if (z)
                    return nums.length - i - 2;
                z = true;
            } else if (c == '5') {
                if (z)
                    return nums.length - i - 2;
                f = true;
            } else if ((c == '2' || c == '7') && f) {
                return nums.length - i - 2;
            }
        }
        if (z)
            return nums.length - 1;
        return nums.length;
    }
}